<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2013 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Common\Behavior;
use Think\Behavior;
use Think\Hook;
defined('THINK_PATH') or exit();

class ChangeOrderBehavior extends Behavior {

    // 行为扩展的执行入口必须是run
    public function run(&$content){
    	//更新订单的状态
		$m = M('YgclOrder');
    	$map['token_time'] = array('LT',time());
    	$map['status'] = 2;
    	
    	$datas = $m->where($map)->select();
    	foreach ($datas as $data){
    		$con = array(
    			'id' => $data['id'],
    			'status' => 3,//已过期
    			'update_time' => Date('Y-m-d H:i:s')
    		);
    		$m->save($con);
    		
    		//已付订单减1
    		if($data['type'] == 'baoming' || $data['type'] == 'midbm'){
    			R('Api/Lessonapi/lesson_number_dec',array('tid'=>$data['termid'],'lid'=>$data['lid']));
    		}
    	} 
    }
}